<?php
namespace app\index\controller;

use app\index\service\Login;
use think\Request;
use think\Session;

class Index extends BaseController
{
    /**
     * 控制器跳转
     */
    public function index()
    {
        $login = new Login();
        $clientid  = $login->getClientId();//用户在线状态码
        return $this->redirect('https://business-test.17jxyx.com/login/?client_id='.$clientid);
    }
    /**
     * 登录页面
     * @return mixed
     */
    public function login(){
        $clientid = Request::instance()->get('client_id');
        if (empty($clientid)){
            $this->redirect('https://business-test.17jxyx.com');
        }
        $this->assign('clientid',$clientid);
        return $this->fetch('index/login');
    }

    /**
     * 权限判断
     * @return string
     */
    public function checkAuth(){
        $data = Request::instance()->param();
        $ak = $data['name'];
        $sk = $data['password'];
        $login = new Login();
        $result =  $login->getToken($ak,$sk);
        if ($result['error_code'] == 0){
            Session::set('user',$data['clientid']);
        }
        return json_encode($result);
    }

    /**
     * 退出
     */
    public function loginOut(){
        $login = new Login();
        $clientid  = $login->getClientId();
        Session::delete('user');
        return $this->redirect('https://business-test.17jxyx.com/login/?client_id='.$clientid);
    }

}
